package mahi.thread;

public class TestCounterThread {
		public static void main(String[] args) {
			
			
//			Counter counter = new Counter();
//			counter.start();
//			System.out.println("After counter extends thread");
//			
//			
//			
//			Counter counter1 = new Counter();
//			counter.run();
//			System.out.println("AFter calling run method");
//			
			
			
			CounterWithRunnable counterRunnnable = new CounterWithRunnable();
			Thread counterRunnnableThread = new Thread(counterRunnnable);
			counterRunnnableThread.start();
			System.out.println("After Counter with Runnable in main");
			
			
		
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		
			
			
			
			
			
			
			
			
			//static methods in thread class
			//sleep method
			 String str[] = {"a","b","c","d"};
			 for (int i = 0;i < str.length;i++) {
		            //Pause for 4 seconds
		           
						try {
							
							Thread.sleep(4000);
						} catch (InterruptedException e) {
							e.printStackTrace();
							return;
						}
					
		            System.out.println(str[i]);
		        }
			 
			 
			
		    }
		
		
		
		
		//Understand Interrupted exception
		//This is an exception that sleep throws when another thread interrupts the current thread while sleep is active
			
		//interrupt (way to interrupt)
		//Thread.interrupted() returns true if interrupt is received
		
		//		if (Thread.interrupted()) {
		//		    throw new InterruptedException();
		//		}
		
		
		

//		Interrupt Status Flag
//		The interrupt mechanism is implemented using an internal flag known as the interrupt status. Invoking Thread.interrupt sets this flag.
//		When a thread checks for an interrupt by invoking the static method Thread.interrupted, interrupt status is cleared. 
//		The non-static isInterrupted method, which is used by one thread to query the interrupt status of another, does not change the interrupt status flag.


}
